#version 400

layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexNormal;

out vec3 LightIntensity;

uniform vec4 LightPosition;     //Light position in eye coords.
uniform vec3 Kd;                //diffuse reflectivity
uniform vec3 Ld;                //Light source intensity

uniform mat4 ModelViewMatrix;
uniform mat3 NormalMatrix;
uniform mat4 Projectionmatrix;
uniform mat4 MVP;

void main(void)
{
    //convert normal and position to eye coords
    vec3 tnorm = normalize(NormalMatrix * VertexNormal);
    vec4 eyeCoords = ModelViewMatrix * vec4(VertexPosition, 1.0);
    vec3 s = normalize(vec3(LightPosition - eyeCoords));

    //the diffuse shading equation
    LightIntensity = Ld * Kd * max( dot(s, tnorm), 0.0);

    //convert position to clip coordinates and pass along
    gl_Position = MVP * vec4(VertexPosition, 1.0);
}
